<template>
  <a-card style="width: 100%">
    <a-button slot="title" @click="$router.back()" type="link" icon="arrow-left" title="返回上一级">返回上一级</a-button>
    <a-button slot="extra" type="danger" title="永久删除" @click="deleteInfo">删除</a-button>
    <a-descriptions title="回收站详情页" bordered size="small">
      <a-descriptions-item label="文件编号">
        {{recycleInfo.id}}
      </a-descriptions-item>
      <a-descriptions-item label="操作人">
        {{recycleInfo.admin ? recycleInfo.admin.userName : ''}}
      </a-descriptions-item>
      <a-descriptions-item label="操作人类型">
        <a-tag
            class="cursor"
            :color="recycleInfo.admin ? recycleInfo.admin.type === 1 ? 'blue': 'green' : ''"
        >
          {{ recycleInfo.admin ? recycleInfo.admin.type === 1 ? '超级管理员': '管理员' : ''}}
        </a-tag>
      </a-descriptions-item>
      <a-descriptions-item label="删除类型">
        {{recycleInfo.removeType}}
      </a-descriptions-item>
      <a-descriptions-item label="删除日期">
        {{$moment(recycleInfo.removeDate).format('yyyy-MM-DD HH:mm:ss')}}
      </a-descriptions-item>
      <a-descriptions-item label="文件分类">
        <a-tag
            class="cursor"
            :color="recycleInfo.fileType === 1 ? 'green': recycleInfo.fileType === 2 ? 'blue' : 'yellowgreen'"
        >
          {{ recycleInfo.fileType === 1 ? '博客': recycleInfo.fileType === 2 ? '资源' : '资源Pk' }}
        </a-tag>
      </a-descriptions-item>
      <a-descriptions-item label="原因描述" :span="3">
        {{recycleInfo.removeWhy}}
      </a-descriptions-item>
      <a-descriptions-item label="发布者信息" :span="3">
        <div v-if="recycleInfo.fileType === 1">
          <div class="userInfo" v-if="recycleInfo.blogVo.user">
            <div><span class="title">用户名：</span>{{recycleInfo.blogVo.user.userName}}</div>
            <div><span class="title">用户头像：</span>
              <a-avatar class="cursor" title="用户详情" @click="$router.push({name:'userinfo',params:{userId:$encry(recycleInfo.blogVo.user.userId)}})" :src="recycleInfo.blogVo.user.avatar"/>
            </div>
            <div><span class="title">用户头衔：</span><a-tag class="cursor" v-for="(tag,index) in recycleInfo.blogVo.user.rankList || []" :color="tag.rankColor" :key="index">{{tag.rankName}}</a-tag></div>
          </div>
        </div>
        <div v-else-if="recycleInfo.fileType === 2">
          <div class="userInfo" v-if="recycleInfo.resVo.user">
            <div><span class="title">用户id：</span>{{recycleInfo.resVo.user.userId}}</div>
            <div><span class="title">用户名：</span>{{recycleInfo.resVo.user.userName}}</div>
            <div><span class="title">用户头像：</span><a-avatar class="cursor" :src="recycleInfo.resVo.user.avatar"/></div>
            <div><span class="title">用户头衔：</span><a-tag class="cursor" v-for="(tag,index) in recycleInfo.resVo.user.rankList || []" :color="tag.rankColor" :key="index">{{tag.rankName}}</a-tag></div>
          </div>
        </div>
        <div v-else-if="recycleInfo.fileType === 3">
          <div class="userInfo" v-if="recycleInfo.pkVo.user">
            <div><span class="title">用户id：</span>{{recycleInfo.pkVo.user.userId}}</div>
            <div><span class="title">用户名：</span>{{recycleInfo.pkVo.user.userName}}</div>
            <div><span class="title">用户头像：</span><a-avatar class="cursor" :src="recycleInfo.pkVo.user.avatar"/></div>
            <div><span class="title">用户头衔：</span><a-tag class="cursor" v-for="(tag,index) in recycleInfo.pkVo.user.rankList || []" :color="tag.rankColor" :key="index">{{tag.rankName}}</a-tag></div>
          </div>
        </div>
      </a-descriptions-item>

      <a-descriptions-item label="文件信息" :span="3">
        <div class="fileInfo" v-if="recycleInfo.fileType === 1">
          <span class="title">博客编号：</span>{{recycleInfo.blogVo.blogId}} <br/>
          <span class="title">博客标题：</span>{{recycleInfo.blogVo.blogTitle}} <br/>
          <span class="title">博客内容：</span>{{recycleInfo.blogVo.blogContent | textFilter}} <br/>
          <span class="title">博客标签：</span>
          <a-space>
            <a-tag v-for="tag in recycleInfo.blogVo.blogTags || []" :key="tag">
              {{tag}}
            </a-tag>
          </a-space><br/>
          <span class="title">博客点赞数：</span>{{recycleInfo.blogVo.blogNiu}} <br/>
          <span class="title">博客发布时间：</span>{{$moment(recycleInfo.blogVo.blogPushTime).format('yyyy-MM-DD HH:mm:ss')}} <br/>
        </div>
        <div class="fileInfo" v-else-if="recycleInfo.fileType === 2">
          <span class="title">资源编号：</span>{{recycleInfo.resVo.resId}} <br/>
          <span class="title">资源标题：</span>{{recycleInfo.resVo.resTitle}} <br/>
          <span class="title">资源内容：</span>{{recycleInfo.resVo.resDesc | textFilter}} <br/>
          <span class="title">资源标签：</span>
          <a-space>
            <a-tag v-for="tag in recycleInfo.resVo.resTags || []" :key="tag">
              {{tag}}
            </a-tag>
          </a-space><br/>
          <span class="title">资源地址：</span>{{recycleInfo.resVo.resUrl}} <br/>
          <span class="title">资源地址说明：</span>{{recycleInfo.resVo.resUrlDesc}} <br/>
          <span class="title">资源发布时间：</span>{{$moment(recycleInfo.resVo.resPushTime).format('yyyy-MM-DD HH:mm:ss')}} <br/>
        </div>
        <div class="fileInfo" v-else-if="recycleInfo.fileType === 3">
          <span class="title">Pk编号：</span>{{recycleInfo.pkVo.id}} <br/>
          <span class="title">Pk标题：</span>{{recycleInfo.pkVo.pkTitle}} <br/>
          <span class="title">Pk内容：</span>{{recycleInfo.pkVo.pkContent | textFilter}} <br/>
          <span class="title">Pk状态：</span>
          <a-tag :color="recycleInfo.pkVo.pkStatus === 1 ? 'green' : 'red'">
            {{recycleInfo.pkVo.pkStatus === 1 ? '进行中' : '已结束'}}
          </a-tag>
          <br/>
          <span class="title">Pk结束时间：</span>{{$moment(recycleInfo.pkVo.pkEndTime).format('yyyy-MM-DD HH:mm:ss')}} <br/>
          <span class="title">Pk发布时间：</span>{{$moment(recycleInfo.pkVo.pkPublishTime).format('yyyy-MM-DD HH:mm:ss')}} <br/>
        </div>
      </a-descriptions-item>
    </a-descriptions>
  </a-card>
</template>

<script>
import {getRecycleInfo, recycleRemove} from "@/api/recycle";
import encry from '@/utils/encryUtil'
export default {
  name: "detail",
  data(){
    return {
      recycleInfo:{}
    }
  },
  mounted() {
    // 加载回收站详情
    this.loadRecycleDetail();
  },
  methods:{
    // 加载详情
    async loadRecycleDetail(){
      const id = this.$route.params.id;
      if (id){
        const {code,data,msg} = await getRecycleInfo(encry.decrypt(id))
        if (code === 200){
          this.recycleInfo = data;
        }else {
          this.$message.error(msg);
        }
      }
    },
    // 删除回调
    deleteInfo(){
      const _this = this;
      const id = this.recycleInfo.id;
      this.$confirm({
        title: '删除文件',
        content: '确认永久删除该文件嘛?',
        okText: '确认删除',
        okType: 'danger',
        cancelText: '放弃',
        onOk() {
          recycleRemove(id).then(res => {
            const { code,msg } = res;
            if (code === 200){
              _this.$message.success(msg);
              _this.$router.back();
            } else {
              _this.$message.error(msg);
            }
          }).catch(error => {
            console.log(error);
            _this.$message.error("操作异常");
          })
        },
        onCancel() {
          console.log("取消了删除");
        },
      });
    }
  }
}
</script>

<style scoped>
.userInfo,.fileInfo{
  line-height: 30px;
}
.title{
  font-weight: 600;
}
</style>
